Don't look inside target/ for sub-packages
authorAlex Crichton <alex@alexcrichton.com>
Fri, 18 Jul 2014 15:29:40 +0000 (08:29 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 20 Jul 2014 04:50:53 +0000 (21:50 -0700)
When cargo is building itself, it just ends up getting confused because the test
directory is in this location.

src/cargo/ops/cargo_read_manifest.rs
tests/test_cargo_compile.rs

index 2246d221537870bf4466971533bf10830707acd0..e25e108b7d6d89da257b261eaacf379082cf236e 100644 (file)
@@ -18,7 +18,7 @@ pub fn read_package(path: &Path, source_id: &SourceId)
     let data = try!(file.read_to_end());
 
     let layout = project_layout(&path.dir_path());
-    let (manifest, nested) = 
+    let (manifest, nested) =
         try!(read_manifest(data.as_slice(), layout, source_id));
 
     Ok((Package::new(manifest, path, source_id), nested))
@@ -32,11 +32,14 @@ pub fn read_packages(path: &Path,
     log!(5, "looking for root package: {}, source_id={}", path.display(), source_id);
     try!(process_possible_package(path, &mut all_packages, source_id, &mut visited));
 
-    try!(walk(path, true, |dir| {
+    try!(walk(path, true, |root, dir| {
         log!(5, "looking for child package: {}", dir.display());
+        if root && dir.join("target").is_dir() { return Ok(false); }
+        if root { return Ok(true) }
         if dir.filename_str() == Some(".git") { return Ok(false); }
         if dir.join(".git").exists() { return Ok(false); }
-        try!(process_possible_package(dir, &mut all_packages, source_id, &mut visited));
+        try!(process_possible_package(dir, &mut all_packages, source_id,
+                                      &mut visited));
         Ok(true)
     }));
 
@@ -48,15 +51,17 @@ pub fn read_packages(path: &Path,
     }
 }
 
-fn walk(path: &Path, is_root: bool, callback: |&Path| -> CargoResult<bool>) -> CargoResult<()> {
+fn walk(path: &Path, is_root: bool,
+        callback: |bool, &Path| -> CargoResult<bool>) -> CargoResult<()> {
     if path.is_dir() {
-        if !is_root {
-            let continues = try!(callback(path));
-            if !continues { log!(5, "Found submodule at {}", path.display()); return Ok(()); }
+        let continues = try!(callback(is_root, path));
+        if !continues {
+            log!(5, "not processing {}", path.display());
+            return Ok(());
         }
 
         for dir in try!(fs::readdir(path)).iter() {
-            try!(walk(dir, false, |x| callback(x)))
+            try!(walk(dir, false, |a, x| callback(a, x)))
         }
     }
 
index c27f0c11434aa781224b59a2dda9211a188efc84..39544b3712b67d327b7effff12fea348b0ae0232 100644 (file)
@@ -1257,3 +1257,20 @@ test!(deletion_causes_failure {
         "#);
     assert_that(p.cargo_process("cargo-build"), execs().with_status(101));
 })
+
+test!(bad_cargo_toml_in_target_dir {
+    let p = project("world")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {}
+        "#)
+        .file("target/Cargo.toml", "bad-toml");
+
+    assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
+    assert_that(process(p.bin("foo")), execs().with_status(0));
+})